package com.bytedance.article.common.launchcrash;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.SharedPreferences;
import android.provider.Settings;
import android.telephony.TelephonyManager;
import android.text.TextUtils;

import java.io.UnsupportedEncodingException;
import java.util.UUID;

public class c {
    private static volatile UUID a;
    private static String b;

    static {
        c.b = "";
    }

    @SuppressLint("MissingPermission")
    private c(Context arg5) {
        UUID v0_3;
        SharedPreferences v2_1;
        String v0_1;

        if (c.a == null) {
            Class v1 = c.class;
            synchronized (v1) {
                try {
                    if (c.a == null) {
                        String v2 = g.b(arg5);
                        v0_1 = "device_id.xml";
                        if (!TextUtils.isEmpty(((CharSequence) v2))) {
                            v0_1 = v2 + v0_1;
                        }

                        v2_1 = arg5.getSharedPreferences(v0_1, 0);
                        v0_1 = v2_1.getString("device_id", null);
                        if (v0_1 != null) {
                            c.a = UUID.fromString(v0_1);
                            return;
                        }

                        v0_1 = Settings.Secure.getString(arg5.getContentResolver(), "android_id");
                        try {
                            if (!"9774d56d682e549c".equals(v0_1)) {
                                c.a = UUID.nameUUIDFromBytes(v0_1.getBytes("utf8"));
                            } else {
                                v0_1 = ((TelephonyManager) arg5.getSystemService(Context.TELEPHONY_SERVICE)).getDeviceId();
                                if (v0_1 != null) {
                                    v0_3 = UUID.nameUUIDFromBytes(v0_1.getBytes("utf8"));
                                } else {
                                    v0_3 = UUID.randomUUID();
                                }
                                c.a = v0_3;
                                v2_1.edit().putString("device_id", c.a.toString()).commit();
                                return;
                            }

                            v2_1.edit().putString("device_id", c.a.toString()).commit();
                            return;
                        } catch (UnsupportedEncodingException v0_2) {
                            throw new RuntimeException(((Throwable) v0_2));
                        }
                    }
                    return;
                } catch (Throwable v0) {
                    v0.printStackTrace();
                }
            }
        }
    }

    public static String a(Context arg2) {
        String v0_2;
        Class v1 = c.class;
        synchronized (v1) {
            if (TextUtils.isEmpty(c.b)) {
                new c(arg2);
                UUID v0_1 = c.a;
                if (v0_1 != null) {
                    c.b = v0_1.toString();
                }
            }
            v0_2 = c.b;
        }
        return v0_2;
    }
}

